﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-01-31-22:40
//  * @Description:
//  */

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using QFramework;

namespace Code.Utility
{
    public class ObjectCopierUtils:IUtility
    {
        
        public T DeepCopy<T>(T obj)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(memoryStream, obj);
                memoryStream.Seek(0, SeekOrigin.Begin);
                return (T)formatter.Deserialize(memoryStream);
            }
        }
    }
}